package com.sunnada.btfvilg.controller;

import com.sunnada.btfvilg.common.response.Result;
import com.sunnada.btfvilg.common.response.ResultFactory;
import com.sunnada.btfvilg.entity.Package;
import com.sunnada.btfvilg.model.request.DeliParamVo;
import com.sunnada.btfvilg.service.DeliveryService;
import com.sunnada.btfvilg.service.PackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author zsl
 * @title DelliveyController
 * @description: TODO
 */
@RestController
@RequestMapping("delivery")
@Api(tags = "揽件派送管理")
public class DeliveryController {
    @Autowired
    DeliveryService deliveryService;
    @Autowired
    PackageService packageService;

    @PostMapping("/collectPackage")
    @ApiOperation(value = "揽收指定包裹", httpMethod = "POST")
    public Result<Object> collectPackage(@Validated @RequestBody DeliParamVo deliParamVo){
        deliveryService.addDeliverylist(deliParamVo);
        packageService.Packagestate(deliParamVo.getPid(),"揽件中");
        return ResultFactory.success("操作成功", null);
    }

    @PostMapping("/distriPackage")
    @ApiOperation(value = "派件指定包裹", httpMethod = "POST")
    public Result<Object> distriPackage(@Validated @RequestBody DeliParamVo deliParamVo){
        deliveryService.updateDeliverylist(deliParamVo);
        packageService.Packagestate(deliParamVo.getPid(),"派件中");
        return ResultFactory.success("操作成功", null);
    }

    @PostMapping("/transPackage")
    @ApiOperation(value = "运输指定包裹", httpMethod = "POST")
    public Result<Object> transPackage(@Validated @RequestBody DeliParamVo deliParamVo){
        deliveryService.updateDeliverylist(deliParamVo);
        packageService.Packagestate(deliParamVo.getPid(),"运输中");
        return ResultFactory.success("操作成功", null);
    }
}
